---
title: Pull
description: Pull migrations from the target database into a local migrations directory
---

## Command

Assuming that all [example migrations](https://github.com/xataio/pgroll/tree/main/examples) have been applied, running:

```
$ pgroll pull migrations/
```

will write the complete schema history as `.yaml` files to the `migrations/` directory:

```
$ ls migrations/

01_create_tables.yaml
02_create_another_table.yaml
03_add_column_to_products.yaml
04_rename_table.yaml
05_sql.yaml
06_add_column_to_sql_table.yaml
...
```

Use the `--json` flag to pull migrations in JSON format rather than YAML.

If the target directory given to `pgroll pull` does not exist, `pgroll pull` will create it.

If the target directory is empty, `pgroll pull` will pull all migrations from the target database. If the target directory contains migration files, `pgroll pull` will pull only those migrations that don't already exist in the directory.
